/**
 * 详细的地理位置数据类
 * 包含位置的完整信息，包括经纬度、地址信息等
 */
public class GeoLocationData {
    private double latitude;
    private double longitude;
    private String city;
    private String region;
    private String country;
    private String countryCode;
    private String postalCode;
    private String timezone;
    private String isp;
    private String locationSource; // "ip", "gps", "manual"
    private double accuracy; // 位置精度（米）
    private long timestamp; // 获取时间戳
    
    public GeoLocationData() {
        this.timestamp = System.currentTimeMillis();
        this.accuracy = -1; // 未知精度
    }
    
    public GeoLocationData(double latitude, double longitude, String city) {
        this();
        this.latitude = latitude;
        this.longitude = longitude;
        this.city = city;
    }
    
    // Getters and Setters
    public double getLatitude() {
        return latitude;
    }
    
    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }
    
    public double getLongitude() {
        return longitude;
    }
    
    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }
    
    public String getCity() {
        return city;
    }
    
    public void setCity(String city) {
        this.city = city;
    }
    
    public String getRegion() {
        return region;
    }
    
    public void setRegion(String region) {
        this.region = region;
    }
    
    public String getCountry() {
        return country;
    }
    
    public void setCountry(String country) {
        this.country = country;
    }
    
    public String getCountryCode() {
        return countryCode;
    }
    
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }
    
    public String getPostalCode() {
        return postalCode;
    }
    
    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }
    
    public String getTimezone() {
        return timezone;
    }
    
    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }
    
    public String getIsp() {
        return isp;
    }
    
    public void setIsp(String isp) {
        this.isp = isp;
    }
    
    public String getLocationSource() {
        return locationSource;
    }
    
    public void setLocationSource(String locationSource) {
        this.locationSource = locationSource;
    }
    
    public double getAccuracy() {
        return accuracy;
    }
    
    public void setAccuracy(double accuracy) {
        this.accuracy = accuracy;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    /**
     * 检查位置数据是否有效
     */
    public boolean isValid() {
        return city != null && !city.trim().isEmpty() &&
               latitude >= -90 && latitude <= 90 &&
               longitude >= -180 && longitude <= 180;
    }
    
    /**
     * 检查位置数据是否已过期
     */
    public boolean isExpired(long maxAgeMs) {
        return (System.currentTimeMillis() - timestamp) > maxAgeMs;
    }
    
    /**
     * 转换为简单的Location对象
     */
    public Location toLocation() {
        return new Location(city, latitude, longitude, locationSource);
    }
    
    /**
     * 获取显示用的位置字符串
     */
    public String getDisplayString() {
        StringBuilder sb = new StringBuilder();
        if (city != null && !city.isEmpty()) {
            sb.append(city);
        }
        if (region != null && !region.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(region);
        }
        if (country != null && !country.isEmpty()) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(country);
        }
        return sb.toString();
    }
    
    @Override
    public String toString() {
        return String.format("GeoLocationData{city='%s', lat=%.4f, lon=%.4f, source='%s', accuracy=%.0fm}", 
            city, latitude, longitude, locationSource, accuracy);
    }
} 